package com.ruoyi.project.module.img.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.module.img.domain.Img;
import com.ruoyi.project.module.img.service.IImgService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 图片路径 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-11-21
 */
@Controller
@RequestMapping("/module/img")
public class ImgController extends BaseController
{
    private String prefix = "module/img";
	
	@Autowired
	private IImgService imgService;
	
	@RequiresPermissions("module:img:view")
	@GetMapping()
	public String img()
	{
	    return prefix + "/img";
	}
	
	/**
	 * 查询图片路径列表
	 */
	@RequiresPermissions("module:img:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Img img)
	{
		startPage();
        List<Img> list = imgService.selectImgList(img);
		return getDataTable(list);
	}
	
	/**
	 * 新增图片路径
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存图片路径
	 */
	@RequiresPermissions("module:img:add")
	@Log(title = "图片路径", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Img img)
	{		
		return toAjax(imgService.insertImg(img));
	}

	/**
	 * 修改图片路径
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Img img = imgService.selectImgById(id);
		mmap.put("img", img);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存图片路径
	 */
	@RequiresPermissions("module:img:edit")
	@Log(title = "图片路径", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Img img)
	{		
		return toAjax(imgService.updateImg(img));
	}
	
	/**
	 * 删除图片路径
	 */
	@RequiresPermissions("module:img:remove")
	@Log(title = "图片路径", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(imgService.deleteImgByIds(ids));
	}
	
}
